﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml;

namespace LOPA.Actions
{
    public class AppInitAction:BaseAction
    {
        public override void Run()
        {
            _processController.Message = "Application initiating...";
            Stream iconStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Hazoper.ico");
            if(iconStream != null){
                Program.AppIcon = new Icon(iconStream);
            }
            InitGuideWordAndReasonList(Program.Workspace);
        }

        private void InitGuideWordAndReasonList(Workspace workspace)
        {
            List<string> tmp;
            XmlDocument doc = new XmlDocument();
            using (XmlReader reader = XmlReader.Create("./Config/GuideWord.xml")){
                 doc.Load(reader);
            }
            XmlNodeList guideWordlist = doc.SelectNodes("/GuideWordList/GuideWord");
            if(guideWordlist != null){
                foreach (XmlNode guideWordNode in guideWordlist){
                    tmp = new List<string>();
                    string guideWordName = guideWordNode.Attributes["name"].Value;
                    workspace.GuideWordList.Add(guideWordName);
                    XmlNodeList reasonList = guideWordNode.SelectNodes("reason");
                    tmp.Clear();
                    foreach (XmlNode node in reasonList){
                        tmp.Add(node.InnerText);
                    }
                    workspace.ResonList.Add(guideWordName,tmp);
                }
            }
        }
    }
}
